package acaai.filters;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import struct.AcaaiUser;
/**
 * Filtro para evitar que se accese a jsp directamente
 * 
 * @author Jorge Lainfiesta 11142
 *
 */
public class AuthFilter implements Filter {

	private List<String> noAuthNeeded;
	@Override
	public void destroy() {}


	/**
	 * No permite el ingreso directo a jsp
	 */
	@Override
	public void doFilter(ServletRequest req, ServletResponse resp,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
		HttpServletResponse response = (HttpServletResponse) resp; 
		
		//Revisa si se intenta acceder directamente a jsp
		System.out.println("\n\ndoFilter: "+request.getRequestURI());
        if (request.getRequestURI().endsWith(".jsp")) { 
        	response.sendRedirect("/home");
        }
        chain.doFilter(req, resp);
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {}

}
